<?php
/**
 * 登录
 * Enter description here ...
 * @author nijn
 *
 */
class LoginAction extends CAction{

	public $returnUrl;
	public $view = 'login';
	public $modelName = 'AdminLoginForm';
	public function run() {
		$c = $this->controller;
		$model = new $this->modelName();
		$session=new CHttpSession;
  		$session->open();
  		if (empty($session['referrer']))
  			$session['referrer'] = Yii::app()->request->urlReferrer;
		$model->modelName = 'FontLoginIdentity';
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') {
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		if(isset($_POST[$this->modelName])) {
			
			$model->attributes = $_POST[$this->modelName];
			if($model->validate() && $model->login()) {
				Yii::app()->user->setFlash(FLASH::RESULT_SUCCESS, '欢迎您，您已成功登录系统！');
				$referrer = $session['referrer'];
				$session->remove('referrer');
				$c->render('sucess',array('href'=>$referrer));
				Yii::app()->end();
			}
		}
		
		Yii::app()->user->setFlash(FLASH::RESULT_FAILED, '请输入用户名和密码.');
		
		$c->render($this->view,array('model'=>$model));
	}
}

?>